package com.controller;

import com.entity.Staff;
import com.google.gson.Gson;
import com.service.StaffService;
import com.vo.ResponseData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @author Cc
 * 2024-04-25
 */
@WebServlet("/AllStaff")
public class GetStaffServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");

        StaffService staffService = new StaffService();

        List<Staff> allStaff = staffService.findAllStaff();

        ResponseData responseData = new ResponseData(0, "success", allStaff);

        String json = new Gson().toJson(responseData);

        PrintWriter out = resp.getWriter();

        out.print(json);
        out.flush();
        out.close();
    }
}
